#pragma once

#include "export.h"
#include "node.h"
#include <osg/node>
#include <osg/array>
#include <string>
#include <vector>

//----------------------------------------------------------------------
class DENG_EXPORT Morph : public Node
//----------------------------------------------------------------------
{
public:
           Morph(void);
           Morph(Node* parent);
  virtual ~Morph(void);

  virtual bool  Load(std::string filename, std::string geode_name = "");

  virtual bool  AddTarget(std::string filename, std::string geode_name = "");

  //to be used when using more then 3 targets
  virtual void  SetTargetWeight(unsigned int m, float val) {if( m <_weights.size()) _weights[m]=val;};
  virtual float GetTargetWeight(unsigned int m)            {if( m <_weights.size()) return _weights[m]; else return 0;};
  virtual void  ResetWeights()                             { for(size_t i=0; i<_weights.size(); i++ ) _weights[i]=0; };
  
  virtual void  Update();

  //to be used when using less then 3 targets -- automatically calls Update()
  virtual void  SetTargetWeights(Vec v);
  virtual Vec   GetTargetWeights() { return Vec(_weights[0],_weights[1],_weights[2] );};

protected:
  osg::Vec3Array *Morph::FindVertexes(osg::Node* n, std::string geode_name = "");

  typedef std::vector< osg::ref_ptr<osg::Vec3Array> > VertexesList;
  VertexesList                   _targets;
  osg::ref_ptr<osg::Vec3Array>   _node_vert;
  osg::ref_ptr<osg::Vec3Array>   _base_vert;

  int _nv; // base model num_vertexes
  std::vector<float> _weights;
};




